import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../../../l10n/local.dart';
import '../../../../service/global_service.dart';
import 'tech_form_base.dart';

class BatteryTemperatureForm extends StatelessWidget {
  final RxDouble batteryTemperature;
  final double height;
  const BatteryTemperatureForm(this.batteryTemperature,
      {required this.height, super.key});

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      final vehicleType = GlobalService.to.currentVehicleType;
      final low = vehicleType.getBatteryTemperatureLowThreshold();
      final high = vehicleType.getBatteryTemperatureHighThreshold();
      return TechFormBase(
        value: batteryTemperature.value,
        height: height,
        unit: '℃',
        valueLabel: local.battery_temperature,
        icon: Icons.device_thermostat,
        colorBuilder: (temp) {
          if (temp < low) return Colors.blueAccent;
          if (temp > high) return Colors.redAccent;
          return Colors.greenAccent;
        },
        statusBuilder: (temp) {
          if (temp < low) {
            return TechFormStatus(local.undertemperature, Colors.blueAccent);
          }
          if (temp > high) {
            return TechFormStatus(local.overtemperature, Colors.redAccent);
          }
          return TechFormStatus(local.normal, Colors.greenAccent);
        },
        statusIconBuilder: (temp) {
          if (temp < low) return Icons.ac_unit;
          if (temp > high) return Icons.warning_amber_rounded;
          return Icons.device_thermostat;
        },
      );
    });
  }
}
